<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
          "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>QUnit for KEYUTIL EC plain private key reader 'keyutil.js'</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>

<!-- script type="text/javascript" src="qunit.js" /script -->
<!-- link rel="stylesheet" href="qunit.css" type="text/css" media="screen" -->
<script src="http://code.jquery.com/qunit/qunit-1.11.0.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.11.0.css" type="text/css" media="screen"/>

<script src="../ext/jsbn.js"></script>
<script src="../ext/jsbn2.js"></script>
<script src="../ext/prng4.js"></script>
<script src="../ext/rng.js"></script>
<script src="../ext/base64.js"></script>
<script src="../ext/rsa.js"></script>
<script src="../ext/rsa2.js"></script>

<script src="../src/asn1hex-1.1.js"></script>
<script src="../src/rsapem-1.1.js"></script>
<script src="../src/rsasign-1.2.js"></script>

<script src="../ext/cj/cryptojs-312-core-fix.js"></script>
<script src="../ext/cj/x64-core.js"></script>
<script src="../ext/cj/cipher-core_min.js"></script>
<script src="../ext/cj/aes_min.js"></script>
<script src="../ext/cj/tripledes_min.js"></script>
<script src="../ext/cj/enc-base64_min.js"></script>
<script src="../ext/cj/md5_min.js"></script>
<script src="../ext/cj/sha1_min.js"></script>
<script src="../ext/cj/sha256_min.js"></script>
<script src="../ext/cj/sha224_min.js"></script>
<script src="../ext/cj/sha512_min.js"></script>
<script src="../ext/cj/sha384_min.js"></script>
<script src="../ext/cj/ripemd160_min.js"></script>
<script src="../ext/cj/hmac_min.js"></script>
<script src="../ext/cj/pbkdf2_min.js"></script>


<script src="../ext/jsbn.js"></script>
<script src="../ext/jsbn2.js"></script>
<script src="../ext/prng4.js"></script>
<script src="../ext/rng.js"></script>
<script src="../ext/ec.js"></script>
<script src="../ext/ec-patch.js"></script>

<script src="../src/base64x-1.1.js"></script>
<script src="../src/asn1-1.0.js"></script>
<script src="../src/keyutil-1.0.js"></script>
<script src="../src/dsa-2.0.js"></script>
<script src="../src/x509-1.1.js"></script>
<script src="../src/crypto-1.1.js"></script>
<script src="../src/ecdsa-modified-1.0.js"></script>
<script src="../src/ecparam-1.0.js"></script>

<script type="text/javascript">
<!--
$(document).ready(function(){

// ======= TEST ===================================================================================
var K1PRVRAWHEX = "11b5737cf9d93f17c0cb1a84655d3995a02824097effa5edd8ee26381eb5d6c3";
var K1PUBRAWHEX = "04a01532a3c0900053de60fbefefcca58793301598d308b41e6f4e364e388c2711bef432c599148c94143d4ff46c2cb73e3e6a41d7eef23c047ea11e60667de425";

var K1PRVP5HEX = "3077020101042011b5737cf9d93f17c0cb1a84655d3995a02824097effa5edd8ee26381eb5d6c3a00a06082a8648ce3d030107a14403420004a01532a3c0900053de60fbefefcca58793301598d308b41e6f4e364e388c2711bef432c599148c94143d4ff46c2cb73e3e6a41d7eef23c047ea11e60667de425";

var K1PRVP8HEX = "308187020100301306072a8648ce3d020106082a8648ce3d030107046d306b020101042011b5737cf9d93f17c0cb1a84655d3995a02824097effa5edd8ee26381eb5d6c3a14403420004a01532a3c0900053de60fbefefcca58793301598d308b41e6f4e364e388c2711bef432c599148c94143d4ff46c2cb73e3e6a41d7eef23c047ea11e60667de425";

var K1PUBP8HEX = "3059301306072a8648ce3d020106082a8648ce3d03010703420004a01532a3c0900053de60fbefefcca58793301598d308b41e6f4e364e388c2711bef432c599148c94143d4ff46c2cb73e3e6a41d7eef23c047ea11e60667de425"; // k1.pub.p8.der

var K1CERTHEX = "3082017c30820121a003020102020900a6f110b42f4940cd300a06082a8648ce3d040302301a310b3009060355040613025553310b3009060355040a0c024b31301e170d3133303731343032313731375a170d3233303731323032313731375a301a310b3009060355040613025553310b3009060355040a0c024b313059301306072a8648ce3d020106082a8648ce3d03010703420004a01532a3c0900053de60fbefefcca58793301598d308b41e6f4e364e388c2711bef432c599148c94143d4ff46c2cb73e3e6a41d7eef23c047ea11e60667de425a350304e301d0603551d0e04160414c847be327cccff638870757496e2be366c44a8fc301f0603551d23041830168014c847be327cccff638870757496e2be366c44a8fc300c0603551d13040530030101ff300a06082a8648ce3d0403020349003046022100df01c4bf58a06b3fa241824b10569a788ddab80b9dd8bb817936468c82d8401e022100d19175600fd50756f65ead8a0950c1da89b384f47bcf8d62ff917006f7558c27"; // k1.self.cer.der

// _test/0cert_ec/k1.prv.p5p.pem
var K1PRVP5PPEM = (function() {/*
-----BEGIN EC PARAMETERS-----
BggqhkjOPQMBBw==
-----END EC PARAMETERS-----
-----BEGIN EC PRIVATE KEY-----
MHcCAQEEIBG1c3z52T8XwMsahGVdOZWgKCQJfv+l7djuJjgetdbDoAoGCCqGSM49
AwEHoUQDQgAEoBUyo8CQAFPeYPvv78ylh5MwFZjTCLQeb042TjiMJxG+9DLFmRSM
lBQ9T/RsLLc+PmpB1+7yPAR+oR5gZn3kJQ==
-----END EC PRIVATE KEY-----
*/}).toString().match(/\/\*([^]*)\*\//)[1];

var k5PrvP8PPem = "" +
"-----BEGIN PRIVATE KEY-----\n" +
"MIHuAgEAMBAGByqGSM49AgEGBSuBBAAjBIHWMIHTAgEBBEIBRNEQ8Y1gwDMH8pne\n" +
"z9uq4ODLE/KTx7eCzMNKlGRIhx/8Mo2+B9ORKPMFk4on0wFW7T+rp7NpXm1wxTOY\n" +
"HSTf7mWhgYkDgYYABADSmlI0TDURn/W+oZrgkPgC0F/56jGtzDFSTQEodep5E0Sw\n" +
"KvBrWN48PSbxukE9JdXPm2soe1yc9BC/Km6nrQJhnQDeIhUCoVSA8GTZ0EwL1AcT\n" +
"5YfKcvwwCdM4lHRU1jYXti4IpC/pggFT3N+IRFmS6M8gTYzvxCZMDUnYHimDB+1p\n" +
"jw==\n" +
"-----END PRIVATE KEY-----\n";

var k5PubP8Pem = "" +
"-----BEGIN PUBLIC KEY-----\n" +
"MIGbMBAGByqGSM49AgEGBSuBBAAjA4GGAAQA0ppSNEw1EZ/1vqGa4JD4AtBf+eox\n" +
"rcwxUk0BKHXqeRNEsCrwa1jePD0m8bpBPSXVz5trKHtcnPQQvypup60CYZ0A3iIV\n" +
"AqFUgPBk2dBMC9QHE+WHynL8MAnTOJR0VNY2F7YuCKQv6YIBU9zfiERZkujPIE2M\n" +
"78QmTA1J2B4pgwftaY8=\n" +
"-----END PUBLIC KEY-----\n";

test("KEYUTIL.getKeyFromPlainPrivatePKCS8Hex(K1PRVP8HEX) k1.prv.p8p.der", function() {
  var key = KEYUTIL.getKeyFromPlainPrivatePKCS8Hex(K1PRVP8HEX);
  equal(key.isPublic, false, "isPublic");
  equal(key.isPrivate, true, "isPrivate");
  equal(key.curveName, "secp256r1", "curveName");
  equal(key.prvKeyHex, K1PRVRAWHEX, "prvKeyHex");
  equal(key.pubKeyHex, K1PUBRAWHEX, "pubKeyHex");
});

test("KEYUTIL.getKey(K1PRVP5HEX, null, pkcs5prv) k1.prv.p5p.der", function() {
  var key = KEYUTIL.getKey(K1PRVP5HEX, null, "pkcs5prv");
  equal(key.isPublic, false, "isPublic");
  equal(key.isPrivate, true, "isPrivate");
  equal(key.curveName, "secp256r1", "curveName");
  equal(key.prvKeyHex, K1PRVRAWHEX, "prvKeyHex");
  equal(key.pubKeyHex, K1PUBRAWHEX, "pubKeyHex");
});

test("KEYUTIL.getKey(K1PRVP8HEX, null, pkcs8prv) k1.prv.p8p.der", function() {
  var key = KEYUTIL.getKey(K1PRVP8HEX, null, "pkcs8prv");
  equal(key.isPublic, false, "isPublic");
  equal(key.isPrivate, true, "isPrivate");
  equal(key.curveName, "secp256r1", "curveName");
  equal(key.prvKeyHex, K1PRVRAWHEX, "prvKeyHex");
  equal(key.pubKeyHex, K1PUBRAWHEX, "pubKeyHex");
});

test("KEYUTIL.getKey(K1PUBP8HEX, null, pkcs8pub) k1.pub.p8.der", function() {
  var key = KEYUTIL.getKey(K1PUBP8HEX, null, "pkcs8pub");
  equal(key.isPublic, true, "isPublic");
  equal(key.isPrivate, false, "isPrivate");
  equal(key.curveName, "secp256r1", "curveName");
  equal(key.pubKeyHex, K1PUBRAWHEX, "pubKeyHex");
});

test("KEYUTIL.getKey(K1CERTHEX, null, x509pub) k1.self.cer.der", function() {
  var key = KEYUTIL.getKey(K1CERTHEX, null, "x509pub");
  equal(key.isPublic, true, "isPublic");
  equal(key.isPrivate, false, "isPrivate");
  equal(key.curveName, "secp256r1", "curveName");
  equal(key.pubKeyHex, K1PUBRAWHEX, "pubKeyHex");
});

test("KEYUTIL.getKey(K1PRVP5PPEM) EC k1.prv.p5p.pem", function() {
  //alert(K1PRVP5PPEM);
  var key = KEYUTIL.getKey(K1PRVP5PPEM);
  equal(key.isPublic, false, "isPublic");
  equal(key.isPrivate, true, "isPrivate");
  equal(key.curveName, "secp256r1", "curveName");
  equal(key.prvKeyHex, K1PRVRAWHEX, "prvKeyHex");
  equal(key.pubKeyHex, K1PUBRAWHEX, "pubKeyHex");
});

test("KEYUTIL.getKey(PEM) Private P-521 PKCS8", function() {
  var key = KEYUTIL.getKey(k5PrvP8PPem);
  equal(key.isPrivate, true, "is private key");
  equal(key.isPublic, false, "is public key");
  equal(key.type, "EC", "type");
  equal(key.curveName, "secp521r1", "curveName");
  equal(key.prvKeyHex, "0144d110f18d60c03307f299decfdbaae0e0cb13f293c7b782ccc34a946448871ffc328dbe07d39128f305938a27d30156ed3faba7b3695e6d70c533981d24dfee65", "prvKeyHex");
});

test("KEYUTIL.getKey(PEM) Public P-521 PKCS8", function() {
  var key = KEYUTIL.getKey(k5PubP8Pem);
  equal(key.isPrivate, false, "is private key");
  equal(key.isPublic, true, "is public key");
  equal(key.type, "EC", "type");
  equal(key.curveName, "secp521r1", "curveName");
  equal(key.pubKeyHex, "0400d29a52344c35119ff5bea19ae090f802d05ff9ea31adcc31524d012875ea791344b02af06b58de3c3d26f1ba413d25d5cf9b6b287b5c9cf410bf2a6ea7ad02619d00de221502a15480f064d9d04c0bd40713e587ca72fc3009d338947454d63617b62e08a42fe9820153dcdf88445992e8cf204d8cefc4264c0d49d81e298307ed698f", "pubKeyHex");
});

});
-->
</script>
  
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">test markup</div>
<a href="../">TOP</a> | 
<a href="index.html">TEST INDEX</a> | 
<a href="qunit-do-keyutil.html">keyutil</a> | 
<a href="qunit-do-keyutil-rsa.html">keyutil-rsa</a> | 
<a href="qunit-do-keyutil-dsa.html">keyutil-dsa</a> | 
<a href="qunit-do-keyutil-ec.html">keyutil-ec</a> | 
<a href="qunit-do-keyutil-eprv.html">keyutil-eprv</a> | 
<a href="qunit-do-keyutil-pub.html">keyutil-pub</a> | 
</body>
</html>

